<template>
  <div class="numberplateInquiry">
    <c-title :hide="false" text="车牌查询"></c-title>
    <div class="carBox">
      <div class="top">车牌号</div>
      <div class="car_lis">
        <template v-for="(item, index) in selectProvince">
          <div class="crile" :key="index" v-if="index == 2">·</div>
          <div class="proivesBtn" :class="selectInd == index ? 'sd' : ''" @click="provincesShowTap(index)" :key="index">
            <span>{{ item }}</span>
            <div class="cursor"></div>
          </div>
        </template>
      </div>
      <div class="radio_line">
        <van-radio-group v-model="licensePlate" direction="horizontal" @change="radioChange">
          <van-radio name="0" checked-color="#FE5E56">绿牌</van-radio>
          <van-radio name="1" checked-color="#FE5E56">蓝牌</van-radio>
          <van-radio name="2" checked-color="#FE5E56">黄牌</van-radio>
        </van-radio-group>
      </div>
      <car_number_keyboard @clickChild="clickChild" @delete="child_Delete" :ind="selectInd" :show="provincesShow" :keyboardType="keyboardType"></car_number_keyboard>

      <div class="bottom_btn" @click="toSearch">查询</div>
    </div>
  </div>
</template>
<script>
import car_number_keyboard from "../car-manage/components/car-number-keyboard.vue";

export default {
  data() {
    return {
      provincesShow: false,
      selectProvince: ["", "", "", "", "", "", "", ""],
      keyboardType: 1,
      licensePlate: "0",
      selectInd: null,
      radio: "0"
    };
  },
  watch: {
    listChange: function(nval, oval) {
      if (nval) {
        this.selectProvince = ["", "", "", "", "", "", "", ""];
        this.selectInd = 0;
      } else {
        this.selectProvince = ["", "", "", "", "", "", ""];
        this.selectInd = 0;
      }
    }
  },
  computed: {
    listChange() {
      const { radio, licensePlate } = this;
      console.log(licensePlate);
      if (radio == "0" && licensePlate == "0") {
        return true;
      } else {
        return false;
      }
    }
  },
  activated() {},
  methods: {
    radioChange() {
      this.keyboardType = 1;
      this.selectInd = 0;
    },
    async toSearch() {
      let str = [...this.selectProvince].join("");
      if (this.fun.isTextEmpty(str)) {
        return this.$toast("请输入车牌号");
      }
      let json = {
        plate_num: str,
        plate_type: this.licensePlate
      };
      let { data, msg, result } = await $http.post("plugin.store-oil-station.frontend.license-plate.index", json, "");
      if (result) {
        console.log(data);
        // 查询成功才跳转去详情页
        this.$router.push(this.fun.getUrl("InquiryResults", { card_num: str }));
      } else {
        this.$toast(msg);
      }
    },
    provincesShowTap(index) {
      this.provincesShow = true;
      this.selectInd = index;
      if (index == 0) {
        this.keyboardType = 1;
      } else if (index >= 1) {
        this.keyboardType = 2;
      }
    },
    clickChild(e) {
      this.$set(this.selectProvince, e.ind, e.key);
      if (e.ind < this.selectProvince.length - 1) {
        this.selectInd = e.ind + 1;
        if (this.selectInd == 0) {
          this.keyboardType = 1;
        } else if (this.selectInd > 0) {
          this.keyboardType = 2;
        }
      }
    },
    child_Delete(e) {
      this.$set(this.selectProvince, e.ind, "");
    }
  },
  components: { car_number_keyboard }
};
</script>
<style lang="scss" scoped>
.numberplateInquiry {
  .carBox {
    margin: 0.63rem;
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 0.94rem 0.88rem;
    box-sizing: border-box;
    .radio_line {
      margin-top: 0.56rem;
    }
    .radio_line:last-child {
      margin-bottom: 2rem;
    }
    .top {
      font-size: 0.94rem;
      margin-bottom: 0.88rem;
      text-align: left;
    }
    .bottom_btn {
      height: 2.5rem;
      background: #f15353;
      border-radius: 1.28rem;
      margin-top: 2.19rem;
      line-height: 2.5rem;
      color: #ffffff;
      text-align: center;
      font-weight: 500;
      font-size: 0.94rem;
    }
  }
  .car_lis {
    display: flex;
    align-items: center;
    justify-content: space-around;

    .crile {
      font-size: 1rem;
      border: 1rem;
      font-weight: bold;
      margin: 0 0.63rem;
    }
    input,
    .proivesBtn {
      border: 0.03rem solid #d6d6dc;
      width: 2.19rem;
      height: 2.19rem;
      background: #ffffff;
      border-radius: 0.5rem;
      margin-right: 0.25rem;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    .sd {
      border: 1px solid #0099ff;
      box-shadow: 0px 0px 10px #0099ff;
      position: relative;
      .cursor {
        width: 0.0625rem;
        height: 0.9375rem;
        background-color: #0099ff;
        animation: flashing 1.2s infinite steps(1, start);
      }
    }
    @keyframes flashing {
      0%,
      100% {
        background-color: #0099ff;
      }

      50% {
        background-color: transparent;
      }
    }
  }
}
</style>
